import mockjs from 'mockjs';
import { waitMills } from './mockutils';

export default {
  'POST /api/user/list': async (req, res) => {
    await waitMills(500);
    const { pageNo, pageSize } = req.body;
    const mock = {
      success: true,
      total: 100,
    };
    mock[`data|${pageSize}`] = [
      {
        'id|+1': (pageNo - 1) * pageSize + 1,
        username: '@first',
        name: '@cname',
        'disabled|1': false,
        createAt: '@datetime("yyyy-MM-dd HH:mm:ss")',
        createBy: '@first',
      },
    ];
    res.json(mockjs.mock(mock));
  },

  'POST /api/user/del': (req, res) => {
    res.status(401).json({ success: true });
  },

  'POST /api/user/disable': { success: true },

  'POST /api/user/resetPwd': { success: true, data: { password: '123456' } },

  'POST /api/user/add': (req, res) => {
    const { username } = req.body;
    if (username === 'admin') {
      res.json({ success: false, message: '用户admin已存在' });
    } else {
      res.json({ success: true });
    }
  },

  'POST /api/user/update': { success: true },
};
